﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "SampleShared.h"
#include <string>
#include <vector>
#include "OwnerPtr.h"

namespace gcmp
{
    class IMainWindow;
    class IDockManager;
    class IDock;
    class IUiDocumentViewManager;
    class IUiView;
    class IUiDocument;
    class IDocument;
    class IAction;
    class IRibbonGroup;
    class IRibbonContextualPage;
}

namespace Sample
{
    //page
    const std::wstring ID_PAGE_MODULE = L"ModuleLabPage";

    const std::wstring ID_GROUP_MODULE = L"ModuleLabGroup";
    const std::wstring ID_GROUP_MODULE_PICK_CONTEXT = L"ModuleLabConextualPickGroup";
    const std::wstring ID_GROUP_MODULE_SNAP_CONTEXT = L"ModuleLabConextualSnapGroup";

    struct CommandContextDefinition
    {
    public:
        CommandContextDefinition(const std::wstring &name, const std::wstring &commandId,
            const std::wstring &iconPath, const std::wstring &tooltip)
            : Name(name)
            , CommandId(commandId)
            , IconPath(iconPath)
            , Tooltip(tooltip)
        {

        }
    public:
        std::wstring Name;
        std::wstring CommandId;
        std::wstring IconPath;
        std::wstring Tooltip;
    };
    
    struct AddinButton
    {
        std::wstring id;
        std::wstring title;
        std::wstring icon;
        std::vector<AddinButton> subs;
    };

    class SAMPLESHARED_EXPORT SampleUIUtils
    {
    public:
        static gcmp::IMainWindow* GetMainWindow();

        static gcmp::IUiDocumentViewManager* GetUiDocumentViewManager();

        static gcmp::IDockManager* GetDockManager();

        //是否在二维图纸环境下
        static bool IsInDrawingEnvironment();

        static bool IsInProjectEnvironment();

        //设置命令上下文
        static void SetupActionContext(gcmp::IAction *pAction,const std::wstring &pageName,
            const std::wstring& contextualPageCaption,
            const std::vector<CommandContextDefinition> &definitions);

        static bool CreateUiViewDrawing(gcmp::IUiDocument* pUiDocument, const std::wstring viewName, gcmp::IUiView* &pUiViewDrawing);

        static void AddPage(const std::wstring& id, const std::wstring& caption);

        //查找分组
        static gcmp::IRibbonGroup* FindGroup(const std::wstring& pageId, const std::wstring& groupId);

        //获取分组，如果分组不存在，则创建
        static gcmp::IRibbonGroup* GetGroup(const std::wstring& pageId, const std::wstring& groupId, const std::wstring& groupName);

        //向分组中加载按钮
        static bool LoadButtons(gcmp::IRibbonGroup* pGroup, const std::vector<AddinButton>& btns);

        static void SetStatusBarPromptMessage(std::wstring) {};
    };

    /// 模块页面的加载工具类
    class SAMPLESHARED_EXPORT ModuleUIUtils
    {
    public:
        // 创建模块页面中单个模块的上下文页面
        void SetupModuleUI(gcmp::OwnerPtr<gcmp::IRibbonGroup> opRibbonGroup, const std::wstring& contextualPageCaption);
        // 删除当前激活的模块上下文页面
        void RemoveModuleUI();

        static ModuleUIUtils* Get();
    private:
        gcmp::OwnerPtr<gcmp::IRibbonContextualPage> m_opRibbonContextualPage;
    };
}




